﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Webknife.Data;
using System.Windows.Forms;

namespace Com.SoundVideo
{
    public class UserMessage
    {
        public static void GetGrade(ComboBox cmbox)
        {
            try
            {
                string commandtext = "select gid,gradename from us_grade";
                DataTable table = DbHelper.ExecuteDataset(SysConst.DB_NAME, commandtext).Tables[0];
                if (table != null && table.Rows.Count > 0)
                {
                    cmbox.DataSource = table;
                    cmbox.DisplayMember = "gradename";
                    cmbox.ValueMember = "gid";
                }
            }
            catch(Exception ex) {
                SysLog.WriterFileError("系统加载错误:"+ex.Message);
            }
        }
        public static void GetGradeClass(string gradeid, ComboBox cmbox)
        {
            if (gradeid.Length == 0) return;
            string commandtext = "select cid,classname from us_class where acadyear=" + gradeid + "";
            DataTable table = DbHelper.ExecuteDataset(SysConst.DB_NAME, commandtext).Tables[0];
            if (table != null && table.Rows.Count > 0){
                cmbox.DataSource = table;
                cmbox.DisplayMember = "classname";
                cmbox.ValueMember = "cid";
            }
        }
        public static DataTable GetClassStudent(string classid)
        {
            if (classid.Length == 0) return null;
            string commandtext = "select usstuid,stuname,accounts,[image] from us_student us "
                               + " left join  stu_studentinfo stu on us.usstuid=stu.id where us. classid=" + classid + "";
            DataTable table = DbHelper.ExecuteDataset(SysConst.DB_NAME, commandtext).Tables[0];
            return table;
        }
        public static void UpdateStudentImg(string usstuid, string imgfilename)
        {
            if (usstuid.Length == 0 || imgfilename.Length == 0) return;
            string commandtext = "update stu_studentinfo set [image]='" + imgfilename + "' where id=" + usstuid + "";
            try{
                DbHelper.ExecuteNonQuery(SysConst.DB_NAME, commandtext);
            }catch{
                SysLog.WriterFileError(commandtext);
            }
        }
    }
}
